﻿<Window x:Class="Fantacid303.ProcessAffinityControl.Manager.TestWindow"
		xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
		xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		xmlns:vm="clr-namespace:Fantacid303.ProcessAffinityControl.Manager.MainWindowViewModels"
		xmlns:converters="clr-namespace:Fantacid303.ProcessAffinityControl.Manager.Converters"
		xmlns:selectors="clr-namespace:Fantacid303.ProcessAffinityControl.Manager.DataTemplateSelectors"
		xmlns:usercontrols="clr-namespace:Fantacid303.ProcessAffinityControl.Manager.UserControls"
		xmlns:tn="clr-namespace:Hardcodet.Wpf.TaskbarNotification;assembly=Hardcodet.Wpf.TaskbarNotification"
		Title="Process Affinity Control - Manager" Height="464" Width="826"
		Loaded="Window_Loaded" Icon="/Fantacid303.ProcessAffinityControl.Manager;component/Images/AppIcon_Small.ico">
	<Window.Resources>

		<selectors:ConfigTreeViewDataTemplateSelector x:Key="configTreeViewDataTemplateSelector" />
		<converters:EntryDetailVisibilityConverter x:Key="entryDetailVisibilityConverter" />
		<converters:RuleDetailVisibilityConverter x:Key="ruleDetailVisibilityConverter" />

		<HierarchicalDataTemplate x:Key="activeEntry" ItemsSource="{Binding Path=Rules}">
			<Grid>
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="20" />
					<ColumnDefinition />
				</Grid.ColumnDefinitions>
				<Grid.RowDefinitions>
					<RowDefinition Height="20" />
				</Grid.RowDefinitions>
				<Grid.ContextMenu>
					<ContextMenu>
						<MenuItem Header="_Delete" Command="{Binding DataContext.DeleteCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}"/>
						<Separator />
						<MenuItem Header="A_dd Rule" Command="{Binding DataContext.AddRuleCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}"/>
					</ContextMenu>
				</Grid.ContextMenu>
				
				<Image Grid.Column="0" Source="Images\ActiveEntry.ico"></Image>
				<TextBlock	Grid.Column="1"
							HorizontalAlignment="Left"
							VerticalAlignment="Top"
							Text="{Binding Name}"
							TextWrapping="NoWrap"
							Margin="0,0,5,0"/>
			</Grid>
		</HierarchicalDataTemplate>
		<HierarchicalDataTemplate x:Key="inactiveEntry" ItemsSource="{Binding Path=Rules}">
			<Grid>
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="20" />
					<ColumnDefinition Width="*" />
				</Grid.ColumnDefinitions>
				<Grid.RowDefinitions>
					<RowDefinition Height="20" />
				</Grid.RowDefinitions>
				<Grid.ContextMenu>
					<ContextMenu>
						<MenuItem Header="Set _Active" Command="{Binding DataContext.SetActiveCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}" />
						<MenuItem Header="_Delete" Command="{Binding DataContext.DeleteCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}" />
						<Separator />
						<MenuItem Header="A_dd Rule" Command="{Binding DataContext.AddRuleCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}"/>
					</ContextMenu>
				</Grid.ContextMenu>

				<Image Grid.Column="0" Source="Images\InactiveEntry.ico"></Image>
				<TextBlock Grid.Column="1"
									HorizontalAlignment="Left"
									VerticalAlignment="Top"
									Text="{Binding Name}"
									TextWrapping="NoWrap" 
									Margin="0,0,5,0"/>
			</Grid>
		</HierarchicalDataTemplate>
		<HierarchicalDataTemplate x:Key="rule" >
			<Grid>
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="20" />
					<ColumnDefinition />
				</Grid.ColumnDefinitions>
				<Grid.RowDefinitions>
					<RowDefinition Height="20" />
				</Grid.RowDefinitions>
				<Grid.ContextMenu>
					<ContextMenu>
						<MenuItem Header="_Delete" Command="{Binding DataContext.DeleteCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}" />
					</ContextMenu>
				</Grid.ContextMenu>

				<Image Grid.Column="0" Source="Images\Rule.ico"></Image>
				<TextBlock Grid.Column="1"
									HorizontalAlignment="Left"
									VerticalAlignment="Top"
									Text="{Binding ProcessName}"
									TextWrapping="NoWrap"
									Margin="0,0,5,0"/>
			</Grid>
		</HierarchicalDataTemplate>
	</Window.Resources>
	<Grid >
		<tn:TaskbarIcon
      x:Name="trayIcon"
      IconSource="/Images/AppIcon_Small.ico"
      ToolTipText="The Process Affinity Control utility has been minimized. Click on this icon to show the utility again.">

				<!-- Set a simple context menu  -->
			<tn:TaskbarIcon.ContextMenu>
				<ContextMenu>
					<ContextMenu.Resources>
						<Style x:Key="trayContextMenuStyle" TargetType="{x:Type MenuItem}">
							<Setter Property="IsCheckable" Value="True" />
							<Setter Property="MenuItem.Header" Value="{Binding Name}"/>
							<Setter Property="MenuItem.Command" Value="{Binding SetActiveAndSaveCommand}" />
						</Style>
					</ContextMenu.Resources>
					<MenuItem Header="_Scenarios" ItemsSource="{Binding ConfigurationEntries}" ItemContainerStyle="{StaticResource trayContextMenuStyle}" />
					<MenuItem Header="E_xit" Click="mnuExit_Click" />
				</ContextMenu>
			</tn:TaskbarIcon.ContextMenu>

		</tn:TaskbarIcon>
		<Menu Height="23" Name="menu1" VerticalAlignment="Top">
			<MenuItem Header="_File" >
				<MenuItem Header="_Save" Command="{Binding SaveCommand}"  >
					<MenuItem.Icon>
						<Image Source="Images/Save.ico"  />
					</MenuItem.Icon>
				</MenuItem>
				<Separator/>
				<MenuItem Header="E_xit" Name="mnuExit" Click="mnuExit_Click" />
			</MenuItem>

		</Menu>
		<TabControl Margin="12,29" Name="tabControl1">
			<TabItem Header="Scenarios" Name="tabConfigEntries">
				<Grid  >
					<TreeView x:Name="trv" 
							  ItemsSource="{Binding ConfigurationEntries}" 
							  ItemTemplateSelector="{StaticResource configTreeViewDataTemplateSelector}" 
							  Margin="6,39,0,6" Width="265" HorizontalAlignment="Left">
						<TreeView.ItemContainerStyle>
							<Style TargetType="{x:Type TreeViewItem}">
								<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
								<Setter Property="TreeViewItem.IsExpanded" Value="True" />
								<Style.Triggers>
									<DataTrigger Binding="{Binding Path=Type}" Value="menu">
										<Setter Property="TreeViewItem.IsSelected" Value="True" />
									</DataTrigger>
								</Style.Triggers>
							</Style>
						</TreeView.ItemContainerStyle>
					</TreeView>
					<GroupBox Margin="277,6,6,6">
					<StackPanel  Name="grid1">
						<usercontrols:ConfigurationEntryEdit x:Name="configurationEntryEdit" DataContext="{Binding SelectedTreeObject}"  Visibility="{Binding Converter={StaticResource entryDetailVisibilityConverter}}" />
						<usercontrols:ConfigurationRuleEdit x:Name="configurationRuleEdit" DataContext="{Binding SelectedTreeObject}" Visibility="{Binding Converter={StaticResource ruleDetailVisibilityConverter}}"/>
						</StackPanel>					
						
					</GroupBox>

					<ToolBar Height="33" Width="271" HorizontalAlignment="Left" VerticalAlignment="Top">

						<Button Command="{Binding AddNewEntryCommand}" >
							<Image Source="Images\AddEntry.ico"></Image>
						</Button>
					</ToolBar>

				</Grid>
			</TabItem>
			<TabItem Header="General Settings" Name="tabGeneralSettings">
				<Grid>
					<usercontrols:GeneralSettingsEdit x:Name="generalSettingsEdit" DataContext="{Binding}" />
				</Grid>
			</TabItem>
			<TabItem Header="Excluded Processes">
				<Grid>
					<usercontrols:SortableListView x:Name="lvConfiguration" ItemsSource="{Binding ExcludedProcesses}" Margin="6" 
						SelectionMode="Single"
						IsSynchronizedWithCurrentItem="True" >
						<ListView.View>
							<GridView>
								<usercontrols:SortableGridViewColumn DisplayMemberBinding="{Binding Path=Name}" SortPropertyName="Name" Width="250" Header="Name" />
							</GridView>
						</ListView.View>
					</usercontrols:SortableListView >
				</Grid>
			</TabItem>
			<TabItem Header="Running Processes">
				<Grid>
					<usercontrols:SortableListView  x:Name="lvProcesses" ItemsSource="{Binding RunningProcesses}" Margin="6,6,6,35">
						<ListView.View>
							<GridView >
								<usercontrols:SortableGridViewColumn DisplayMemberBinding="{Binding Path=PID}" IsDefaultSortColumn="true" SortPropertyName="PID"  Width="50" Header="PID" />
								<usercontrols:SortableGridViewColumn DisplayMemberBinding="{Binding Path=AffinityMask}" SortPropertyName="AffinityMask" Width="150" Header="Affinity Mask"/>
								<usercontrols:SortableGridViewColumn DisplayMemberBinding="{Binding Path=Name}" SortPropertyName="Name" Width="300" Header="Process Name"/>
							</GridView>
						</ListView.View>
					</usercontrols:SortableListView >
					<Button Content="Refresh" Margin="0,0,6,6" Name="button1" Height="23" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="75"
							Command="{Binding RefreshProcessListCommand}" />
				</Grid>
			</TabItem>
		</TabControl>
		<StatusBar Name="statusBar1" Height="22" VerticalAlignment="Bottom" >
			<Label Padding="10,0,0,0" Content="{Binding StatusMessage}" VerticalContentAlignment="Center"  />
		</StatusBar>
	</Grid>
</Window>
